package com.zzg.demo.springbatch.demo.customer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import java.util.function.Function;

/**
 * 自定义处理器
 * 传入I对象，返回O对象
 * @param <I>
 * @param <O>
 */
@Slf4j
public class MyFunctionProcess<I, O> implements ItemProcessor<I, O> {
    // 自定义对传入的数值进行处理的方法
    private final Function<I, O> function;

    public MyFunctionProcess(Function<I, O> function) {
        Assert.notNull(function, "A function is required");
        this.function = function;
    }

    @Nullable
    public O process(I item) {
        return this.function.apply(item);
    }
}